package com.cskaoyan.controller.admin;

import com.cskaoyan.model.admin.bo.BaseParam;

import com.cskaoyan.model.admin.bo.MarketIssueBo;
import com.cskaoyan.model.admin.vo.BaseData1;
import com.cskaoyan.model.admin.vo.BaseRespVo;
import com.cskaoyan.model.admin.vo.BaseRespVoNB;
import com.cskaoyan.model.admin.vo.MarketIssueVo;
import com.cskaoyan.service.admin.AdminIssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: 牛犇
 * @date 2021/11/30 15:54
 */
@RestController
@RequestMapping("admin/issue")
public class AdminIssueController {
    @Autowired
    AdminIssueService adminIssueService;

    @RequestMapping("list")
    public BaseRespVo list(BaseParam param,String question){
        List<MarketIssueVo> list=adminIssueService.list(param,question);
        BaseData1 data = BaseData1.list(list, list.size());
        data.setLimit(param.getLimit());
        data.setPages(list.size()/param.getLimit());
        data.setPage(param.getPage());
        return BaseRespVo.ok(data);
    }

    @PostMapping("delete")
    public BaseRespVoNB delete(@RequestBody MarketIssueBo marketIssueBo){
        adminIssueService.deleteMarketIssue(marketIssueBo.getId());
        return BaseRespVoNB.ok();
    }

    @PostMapping("update")
    public BaseRespVoNB update(@RequestBody MarketIssueBo marketIssueBo){
        adminIssueService.updateMarketIssue(marketIssueBo);
        return  BaseRespVoNB.ok();
    }

    @PostMapping("create")
    public BaseRespVo create(@RequestBody MarketIssueBo marketIssueBo){
        MarketIssueVo marketIssueVo=adminIssueService.createMarketIssue(marketIssueBo);
        return BaseRespVo.ok(marketIssueVo);
    }


 }
